# -*- coding:utf-8 -*-

import pymysql

pymysql.install_as_MySQLdb()

class DBMgr(object):
    def __init__(self):        
        self.conn = pymysql.connect(
            host='192.168.10.115',
            port=3306,
            user='shipei',
            passwd='a123456!',
            db='oa',
            charset="utf8"
        )

        self.db = self.conn.cursor()

    def execute(self, sql):
        try:
            self.db.execute(sql)
        except Exception as e:
            print(e)

    def commit(self):
        try:
            self.conn.commit()
        except Exception as e:
            self.conn.rollback()
            print(e)

    def fetchone(self):
        try:
            return self.db.fetchone()
        except Exception as e:
            print(e)
            return []

    def fetchall(self):
        try:
            return self.db.fetchall()
        except Exception as e:
            print(e)
            return []

    def fetchmany(self, len):
        try:
            return self.db.fetchmany(len)
        except Exception as e:
            print(e)
            return []

